//
//  bNmycrJLCFMineSettingChangePasswordControllerXFCPIY.m
//  qcb_ios
//
//  Created by Ji on 2018/8/31.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "bNmycrJLCFMineSettingChangePasswordControllerXFCPIY.h"
#import "sHkPtEJLCFMineRequestozAYZs.h"

#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

@interface bNmycrJLCFMineSettingChangePasswordControllerXFCPIY ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *aueeoLoldPassTextFieldojYUjP;

@property (nonatomic, strong) UITextField *HPkWzFnowPassTextFieldNFeMmC;

@property (nonatomic, strong) UITextField *FOQLaxreNowPassTextFieldLLDuNt;

@end

@implementation bNmycrJLCFMineSettingChangePasswordControllerXFCPIY

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addNavigationBar];
    self.navigationBar.title = @"更改密码";
    
    self.view.backgroundColor = QTZ_Gray237;
    [self configView];
}

- (void)configView
{
    UIView *oldPassBgView = [[UIView alloc] initWithFrame:CGRectMake(0, NAVBAR_HEIGHT + 12, FULL_WIDTH, 38)];
    oldPassBgView.backgroundColor = QTZ_White;
    [self.view addSubview:oldPassBgView];
    self.aueeoLoldPassTextFieldojYUjP = [[UITextField alloc] initWithFrame:CGRectMake(18, 0, FULL_WIDTH - 36, 38)];
    self.aueeoLoldPassTextFieldojYUjP.font = FONT(15);
    self.aueeoLoldPassTextFieldojYUjP.placeholder = @"请输入原登录密码";
    self.aueeoLoldPassTextFieldojYUjP.secureTextEntry = YES;
    self.aueeoLoldPassTextFieldojYUjP.backgroundColor = QTZ_White;
    self.aueeoLoldPassTextFieldojYUjP.delegate = self;
    self.aueeoLoldPassTextFieldojYUjP.returnKeyType = UIReturnKeyDone;
    self.aueeoLoldPassTextFieldojYUjP.clearButtonMode = UITextFieldViewModeWhileEditing;
    [oldPassBgView addSubview:self.aueeoLoldPassTextFieldojYUjP];
    
    UIView *nowPassBgView = [[UIView alloc] initWithFrame:CGRectMake(0, oldPassBgView.bottom + 12, FULL_WIDTH, 77)];
    nowPassBgView.backgroundColor = QTZ_White;
    [self.view addSubview:nowPassBgView];
    self.HPkWzFnowPassTextFieldNFeMmC = [[UITextField alloc] initWithFrame:CGRectMake(18, 0, FULL_WIDTH - 36, 38)];
    self.HPkWzFnowPassTextFieldNFeMmC.font = FONT(15);
    self.HPkWzFnowPassTextFieldNFeMmC.placeholder = @"请输入新登录密码";
    self.HPkWzFnowPassTextFieldNFeMmC.secureTextEntry = YES;
    self.HPkWzFnowPassTextFieldNFeMmC.backgroundColor = QTZ_White;
    self.HPkWzFnowPassTextFieldNFeMmC.delegate = self;
    self.HPkWzFnowPassTextFieldNFeMmC.returnKeyType = UIReturnKeyDone;
    self.HPkWzFnowPassTextFieldNFeMmC.clearButtonMode = UITextFieldViewModeWhileEditing;
    [nowPassBgView addSubview:self.HPkWzFnowPassTextFieldNFeMmC];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.HPkWzFnowPassTextFieldNFeMmC.left, self.HPkWzFnowPassTextFieldNFeMmC.bottom, self.HPkWzFnowPassTextFieldNFeMmC.width, 1)];
    line.backgroundColor = QTZ_Gray237;
    [nowPassBgView addSubview:line];
    
    self.FOQLaxreNowPassTextFieldLLDuNt = [[UITextField alloc] initWithFrame:CGRectMake(18, 39, FULL_WIDTH - 36, 38)];
    self.FOQLaxreNowPassTextFieldLLDuNt.font = FONT(15);
    self.FOQLaxreNowPassTextFieldLLDuNt.placeholder = @"请再次确认新登录密码";
    self.FOQLaxreNowPassTextFieldLLDuNt.secureTextEntry = YES;
    self.FOQLaxreNowPassTextFieldLLDuNt.backgroundColor = QTZ_White;
    self.FOQLaxreNowPassTextFieldLLDuNt.delegate = self;
    self.FOQLaxreNowPassTextFieldLLDuNt.returnKeyType = UIReturnKeyDone;
    self.FOQLaxreNowPassTextFieldLLDuNt.clearButtonMode = UITextFieldViewModeWhileEditing;
    [nowPassBgView addSubview:self.FOQLaxreNowPassTextFieldLLDuNt];
    
    UILabel *edHyphtipsLabelTVYPVW = [UILabel labelWithText:@"请使用6-15位数字或字母" textColor:QTZ_Gray118 font:FONT(9)];
    edHyphtipsLabelTVYPVW.left = 18;
    edHyphtipsLabelTVYPVW.top = nowPassBgView.bottom + 7;
    [self.view addSubview:edHyphtipsLabelTVYPVW];
    
    UIButton *confirmBtn = [[UIButton alloc] initWithFrame:CGRectMake(18, edHyphtipsLabelTVYPVW.bottom + 20, FULL_WIDTH - 36, 38)];
    confirmBtn.titleLabel.font = FONT(15);
    [confirmBtn setTitleColor:QTZ_White forState:0];
    [confirmBtn setTitle:@"确认修改" forState:0];
    [confirmBtn setBackgroundColor:Theme_Color];
    [confirmBtn addTarget:self action:@selector(handleConfirm) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.layer.cornerRadius = 5;
    [self.view addSubview:confirmBtn];
    
}

- (void)handleConfirm
{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setSafeObject:[[NSString stringWithFormat:@"%@%@", [self.aueeoLoldPassTextFieldojYUjP.text MD5], [JLCFRegisterService shareService].phone] MD5] forKey:@"oPassword"];
    [params setSafeObject:[[NSString stringWithFormat:@"%@%@", [self.HPkWzFnowPassTextFieldNFeMmC.text MD5], [JLCFRegisterService shareService].phone] MD5] forKey:@"nPassword"];
    [params setSafeObject:[[NSString stringWithFormat:@"%@%@", [self.FOQLaxreNowPassTextFieldLLDuNt.text MD5], [JLCFRegisterService shareService].phone] MD5] forKey:@"rPassword"];
    
    [sHkPtEJLCFMineRequestozAYZs changePassWithParams:params loadingInView:self.view success:^{
        [self showNotice:@"修改成功"];
        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] popViewControllerAnimated:YES];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)dZrvUEtextFieldRRHEAtShouldReturn:(UITextField *)dZrvUEtextFieldRRHEAt{
    return [dZrvUEtextFieldRRHEAt resignFirstResponder];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (BOOL)dZrvUEtextFieldRRHEAt:(UITextField *)dZrvUEtextFieldRRHEAt shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ALPHANUM] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    
    if (dZrvUEtextFieldRRHEAt == self.aueeoLoldPassTextFieldojYUjP) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        //so easy
        else if (self.aueeoLoldPassTextFieldojYUjP.text.length >= 15) {
            self.aueeoLoldPassTextFieldojYUjP.text = [dZrvUEtextFieldRRHEAt.text substringToIndex:15];
            return NO;
        }
    }
    
    if (dZrvUEtextFieldRRHEAt == self.HPkWzFnowPassTextFieldNFeMmC) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        //so easy
        else if (self.HPkWzFnowPassTextFieldNFeMmC.text.length >= 15) {
            self.HPkWzFnowPassTextFieldNFeMmC.text = [dZrvUEtextFieldRRHEAt.text substringToIndex:15];
            return NO;
        }
    }
    
    if (dZrvUEtextFieldRRHEAt == self.FOQLaxreNowPassTextFieldLLDuNt) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
            return YES;
        }
        //so easy
        else if (self.FOQLaxreNowPassTextFieldLLDuNt.text.length >= 15) {
            self.FOQLaxreNowPassTextFieldLLDuNt.text = [dZrvUEtextFieldRRHEAt.text substringToIndex:15];
            return NO;
        }
    }
    
    return [string isEqualToString:filtered];
}


@end
